//
//  leadViewController.m
//  Assistant
//
//  Created by 安徽威思特 on 16/12/29.
//  Copyright © 2016年 秦慕乔. All rights reserved.
//

#import "leadViewController.h"
#import "LoginViewController.h"

@interface leadViewController ()

@end


@implementation leadViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self createScrollView];
    self.automaticallyAdjustsScrollViewInsets = NO;
    //[self createPageController];
}


-(void)createScrollView
{
    UIScrollView * scrollView = [[UIScrollView alloc] init];
    scrollView.delegate = self;
    scrollView.frame = self.view.bounds;
    [self.view addSubview:scrollView];
    
    CGFloat imageViewW = self.view.bounds.size.width;
    CGFloat imageViewH = self.view.bounds.size.height;
    for (int i = 0; i < 3; i ++) {
        UIImageView *imageView = [[UIImageView alloc] init];
        UIImage * image = [UIImage imageNamed:[NSString stringWithFormat:@"flash%d.png",i+1]];
        imageView.image = image;
        CGFloat imageViewX = imageViewW * i;
        imageView.frame = CGRectMake(imageViewX, 0, imageViewW, imageViewH);
        
        [scrollView addSubview:imageView];
        
        [self setUpRightImageViewBtn:imageView];
        
        if (i == 2) {
            [self setUpLastImageViewBtn:imageView];
        }
    }
    scrollView.contentSize = CGSizeMake(imageViewW * 3, 0);
    scrollView.showsVerticalScrollIndicator = NO;
    scrollView.showsHorizontalScrollIndicator = NO;
    scrollView.pagingEnabled = YES;
    scrollView.bounces = NO;
}

-(void)setUpRightImageViewBtn:(UIImageView *)imageView
{
    // 让imageView能跟用户交互
    imageView.userInteractionEnabled = YES;
    
    // 添加开始按钮
    UIButton *startButton = [UIButton buttonWithType:UIButtonTypeCustom];
    startButton.frame = CGRectMake(WIDTH-40-20, 20, 40, 40);
    [startButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [startButton addTarget:self action:@selector(start1) forControlEvents:UIControlEventTouchUpInside];
    [imageView addSubview:startButton];
}

-(void)setUpLastImageViewBtn:(UIImageView *)imageView
{
    // 让imageView能跟用户交互
    imageView.userInteractionEnabled = YES;
    
    // 添加开始按钮
    UIButton *startButton = [UIButton buttonWithType:UIButtonTypeCustom];
    startButton.frame = CGRectMake(WIDTH*0.26, HEIGHT*0.9, 150, 40);
    [startButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [startButton addTarget:self action:@selector(start1) forControlEvents:UIControlEventTouchUpInside];
    [imageView addSubview:startButton];
    
}

-(void)start1
{
    LoginViewController *lvc = [[LoginViewController alloc]init];
    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:lvc];
    self.view.window.rootViewController = nav;
    
}

-(void)createPageController
{
    // 添加
    UIPageControl *pageControl = [[UIPageControl alloc] init];
    pageControl.numberOfPages = 3;
    CGFloat centerX = self.view.frame.size.width * 0.5;
    CGFloat centerY = self.view.frame.size.height - 30;
    pageControl.center = CGPointMake(centerX, centerY);
    pageControl.bounds = CGRectMake(0, 0, 100, 30);
    pageControl.userInteractionEnabled = NO;
    [self.view addSubview:pageControl];
    self.pageControl = pageControl;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    // 取出水平方向上滚动的距离
    CGFloat offsetX = scrollView.contentOffset.x;
    // 求出页码
    double pageDouble = offsetX / scrollView.frame.size.width;
    int pageInt = (int)(pageDouble + 0.5);
    self.pageControl.currentPage = pageInt;
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    self.navigationController.navigationBar.hidden = YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
